import React from "react";

export const emptyParams = {
  summaryType: "byDay", // 按日：byDay, 按月：byMonth
  startDate: "", // 开始日期
  endDate: "", // 结束日期
  year: "",
  months: [],
};

export function getEllipsisCell(cn, v, maxWidth) {
  return (
    <span
      className={cn}
      style={{
        display: "inline-block",
        maxWidth,
      }}
      title={v}
    >
      {v}
    </span>
  );
}

export function getColumns() {
  const columns = [
    {
      title: "账期",
      dataIndex: "date",
      render: (text, record) => {
        let label = "";
        if (record.year) {
          label = `${record.year}年`;
        }
        if (record.month) {
          label += `${record.month}月`;
        }
        if (record.day) {
          label += `${record.day}日`;
        }
        return <span>{label}</span>;
      },
    },
    {
      title: "流程数量",
      dataIndex: "modelCount",
      render: (v) => this.getEllipsisCell(v, 79),
    },
    {
      title: "实例数量",
      dataIndex: "processInstanceCount",
      render: (v) => this.getEllipsisCell(v, 79),
    },
    {
      title: "正常",
      dataIndex: "normalCount",
      render: (v) => this.getEllipsisCell(v, 79),
    },
    {
      title: "预警",
      dataIndex: "warningCount",
      render: (v) => this.getEllipsisCell(v, 79),
    },
    {
      title: "超时",
      dataIndex: "timeoutCount",
      render: (v) => this.getEllipsisCell(v, 79),
    },
    {
      title: "错误",
      dataIndex: "errorCount",
      render: (v) => this.getEllipsisCell(v, 79),
    },
  ];
  return columns;
}
//
// 页码页数改变
export function handlePageChange(pageNum, pageSize) {
  this.setState({ page: { pageNum, pageSize } }, () => {
    this.initData();
  });
}

export function getPageProps(current, pageSize, total) {
  return {
    showQuickJumper: true,
    showSizeChanger: true,
    pageSizeOptions: ["10", "20", "30", "40"],
    current,
    pageSize,
    total,
    onChange: this.handlePageChange,
    onShowSizeChange: this.handlePageChange,
  };
}

// 加载应用数据
export function initAppListData() {
  const { dispatch } = this.props;
  dispatch({ type: "appListMenu/getAppListData" }).then((res) => {
    const { appListMenuData = {} } = res || {};
    if (appListMenuData && appListMenuData.length > 0) {
      // const parameter = this.searchParams
      // this.searchParams.tenantId = `${appListMenuData[0].id}`;
      // parameter.appId = datas.app[0].id
      // this.setState({
      //   selectedKeys: [`${appListMenuData[0].id || "0"}`],
      // });
      this.initData();
    }
  });
}

export function initData() {
  const { dispatch } = this.props;
  const params = this.getQueryParam();
  dispatch({
    type: "Report/getProcessInstanceTotal",
    payload: {
      ...params,
    },
  });
}
